﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using EQT.Model;

/// <summary>
/// 检验结果附件（图片等）的上传。
/// </summary>
public class UploadResultAttachment : IUploadFile
{
    private DaProductCheckContract dacontract = DevFuture.Common.WorkContext.AppCtx.GetObject("DaProductCheckContract") as DaProductCheckContract;
    private DaTfiles datf = DevFuture.Common.WorkContext.AppCtx.GetObject("DaTfiles") as DaTfiles;
    private DaDirFile dadf = DevFuture.Common.WorkContext.AppCtx.GetObject("DaDirFile") as DaDirFile;

    public UploadResultAttachment()
    {
        
    }

    #region IUploadFile 成员

    public void InitUpload(IUploadPage up, System.Collections.Specialized.NameValueCollection nvc)
    {
        #region 为产品检验项上传附件
        //给定任务的ID，给定通知标题，给定返回URL
        string strCtid = nvc["CTID"];//获取任务ID号

        if (String.IsNullOrEmpty(strCtid) || strCtid.Trim().Length == 0)
        {
            Utility.SiteError("缺失所必需的参数【任务编号】", up.Response);
        }
        else
        {
            up.SetConfigValue("CTID", strCtid.Trim());

            up.SetPageTitle(String.Format("为任务【{0}】上传附件：",
                strCtid));
        }
        #endregion
    }

    public int Upload1(IUploadPage up, EQT.Model.MoTfiles file, string opter_id)
    {
        MoRefFile modref = new MoRefFile();
        modref.Eid = up.GetConfigValue("CTID").ToString()+"_0";
        modref.FileId = file.FileId;
        modref.RfId = SequenceKeys.GenerateReferFileID();
        try
        {
            return datf.AddFileEx(file, modref);
            //return datfile.AddFileProduct(file, modref, modref.Eid, up.GetConfigValue("FILETYPE").ToString());
        }
        catch (DalException de)
        {
            Utility.GlobalLog.Error("添加单个文件失败!", de);
            Utility.SiteError("添加单个文件失败!", up.Response);
            return -1; 
        }
    }

    public int UploadedMuliti(IUploadPage up, System.Collections.Generic.List<EQT.Model.MoTfiles> files, string opter_id)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    public string GetReturnUrl(IUploadPage up)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    #endregion
}
